package com.pda.common.tools;

import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

//Toast工具
public class ToastUtils {
    public static boolean isShow = true;
    private static Handler sHandler = new Handler(Looper.getMainLooper());
    private static Toast sToast;

    private ToastUtils() {
        throw new UnsupportedOperationException("cannot be instantiated");
    }

    /**
     * 短时间显示Toast
     */
    public static void showShort(Context context, String message) {
        Toast toast = Toast.makeText(context, message, Toast.LENGTH_SHORT);
        LinearLayout linearLayout = (LinearLayout) toast.getView();
        TextView messageTextView = (TextView) linearLayout.getChildAt(0);
        messageTextView.setTextSize(12);
        toast.show();
    }

    /**
     * 长时间显示Toast
     */
    public static void showLong(Context context, String message) {
        Toast toast = Toast.makeText(context, message, Toast.LENGTH_LONG);
        LinearLayout linearLayout = (LinearLayout) toast.getView();
        TextView messageTextView = (TextView) linearLayout.getChildAt(0);
        messageTextView.setTextSize(12);
        toast.show();
    }

    /**
     * 任意线程发送Toast
     *
     * @param context
     * @param text
     */
    public static void showSafeToast(final Context context, final String text) {
        sHandler.post(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
            }
        });
    }

}
